package cn.fj.hrm.listener;

import cn.fj.hrm.basic.constant.MQContant;
import cn.fj.hrm.domain.Msg;
import com.rabbitmq.client.Channel;
import org.springframework.amqp.core.Message;
import org.springframework.amqp.rabbit.annotation.RabbitListener;
import org.springframework.stereotype.Component;

import java.io.IOException;

@Component
public class QueueListener {

    @RabbitListener(queues = MQContant.QUEUE_HRM_SMS)
    public void receiveSMS(Msg msg, Message message, Channel channel){
        try {
            System.out.println("SMS消费者收到消息：" + msg.getContent());
            //发送短信

            //手动签收
            channel.basicAck(message.getMessageProperties().getDeliveryTag(), false);
        } catch (IOException e) {
            e.printStackTrace();
        }
    }
    @RabbitListener(queues = MQContant.QUEUE_HRM_EMAIL)
    public void receiveEMAIL(Msg msg, Message message, Channel channel){
        try {
            System.out.println("EMAIL消费者收到消息：" + msg.getContent());
            //发送邮件

            //手动签收
            channel.basicAck(message.getMessageProperties().getDeliveryTag(), false);
        } catch (IOException e) {
            e.printStackTrace();
        }
    }

}
